﻿using AngleExpress.utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AngleExpress.software
{
    class DingTalk : ISoftware
    {
        public override void OpenSoftware(string username, string password, string otherParam)
        {
            string path = FindDingTalk();
            if (path == "")
            {
                throw new Exception("没有找到钉钉安装路径");
            }
            ProcessStartInfo info = new ProcessStartInfo();
            info.UseShellExecute = true;
            info.FileName = path;
            info.Arguments = "";
            try
            {
                Process pro = Process.Start(info);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        string FindDingTalk()
        {
            String[] drivers = Environment.GetLogicalDrives();
            foreach (String driver in drivers)
            {
                try
                {
                    string filePath = Utils.TraverseDir(driver, driver, "DingtalkLauncher.exe", 3);
                    if (filePath != "")
                        return filePath;
                }
                catch
                {
                    continue;
                }
            }
            return "";
        }

     
    }
}
